<%-- 
  -- Body Edit para Customer
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<script src="<html:rewrite page='/protected/script/util.js'/>" type="text/javascript"></script>

<%-- Para EXT --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/style/dragdrop.css'/>" id="styleFile"/>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    function modify() {
		if (!validate()) {
			return;
		}
		
        var idObj = $("modifyId");
        var nameObj = $("modifyNameId");
        var corporateNameObj = $("modifyCorporateNameId");
        var documentObj = $("modifyDocumentId");
        var termsObj = $("modifyTermsId");
        var emailObj = $("modifyEmailId");
        var phoneObj = $("modifyPhoneId");
        var mobileObj = $("modifyMobileId");
        var addressStreetObj = $("modifyAddressStreetId");
        var addressNumberObj = $("modifyAddressNumberId");
		var addressFloorObj = $("modifyAddressFloorId");
		var addressRoomObj = $("modifyAddressRoomId");
		var addressZipCodeObj = $("modifyAddressZipCodeId");
		var addressCityObj = $("modifyAddressCityId");
        var addressTownObj = $("modifyAddressTownId");
        var contactObj = $("modifyContactId");
        
        idObj.value = $("customerId").value;
        nameObj.value = $("nameId").value;
        corporateNameObj.value = $("corporateNameId").value;
        documentObj.value = $("documentId").value;
        termsObj.value = $("termsId").value;
        emailObj.value = $("emailId").value;
        phoneObj.value = $("phoneId").value;
        mobileObj.value = $("mobileId").value;
        addressStreetObj.value = $("addressStreetId").value;
        addressNumberObj.value = $("addressNumberId").value;
        addressFloorObj.value = $("addressFloorId").value;
        addressRoomObj.value = $("addressRoomId").value;
        addressZipCodeObj.value = $("addressZipCodeId").value;
        addressCityObj.value = $("addressCityId").value;
        addressTownObj.value = $("addressTownId").value;
        contactObj.value = $("contactId").value;
        
        var form = $("modifyCustomerFormId");
        form.submit();
    }
    
    function validate() {
    	if (Util.valid.isBlank($("nameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el nombre. ');
            $("nameId").focus();
            return false;
        }
		if (Util.valid.isBlank($("corporateNameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la raz&oacute;n social. ');
            $("corporateNameId").focus();
            return false;
        }
        if (Util.valid.isBlank($("documentId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el documento. ');
            $("documentId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressStreetId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la calle. ');
            $("addressStreetId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressNumberId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el numero. ');
            $("addressNumberId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressCityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la ciudad. ');
            $("addressCityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressTownId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la localidad. ');
            $("addressTownId").focus();
            return false;
        }
        return true;
    }
    
     /* Lleva a la cuenta corriente del cliente
     */
    var showCustomerAccount = function() {
        // Se saca del customerId y se lo pone en customerIdId del showCustomerAccountFormId
        $("customerIdId").value = $("customerId").value;
        
        var form = $("showCustomerAccountFormId");
        form.submit();
    }
</script>

<div class="errors">
    <html:errors />
</div>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showCustomer.do" styleId="customerFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden name="customerForm" property="id" styleId="customerId"/>

    <h2>Modificaci&oacute;n de cliente</h2>
    
    <div class="customerEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nombre*
                </td>
                <td class="tableDataValue">
                    <html:text property="name" name="customerForm" styleId="nameId" size="40" maxlength="40" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Raz&oacute;n Social*
                </td>
                <td class="tableDataValue">
                    <html:text property="corporateName" name="customerForm" styleId="corporateNameId" size="40" maxlength="255" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Documento* (DNI/CUIT/CUIL)
                </td>
                <td class="tableDataValue">
                    <html:text property="document" name="customerForm" styleId="documentId" size="14" maxlength="14" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Condici&oacute;n Impositiva
                </td>
                <td class="tableDataValue">
					<html:select property="termTypeSelected" styleClass="allSelects" styleId="termsId">
                        <html:optionsCollection property="termTypeCollection"/>
                    </html:select>
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel&eacute;fono
                </td>
                <td class="tableDataValue">
                    <html:text property="phone" name="customerForm" styleId="phoneId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Celular
                </td>
                <td class="tableDataValue">
                    <html:text property="mobile" name="customerForm" styleId="mobileId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email
                </td>
                <td class="tableDataValue">
                    <html:text property="email" name="customerForm" styleId="emailId" size="50" maxlength="75" />
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    Direcci&oacute;n
                </td>
                <td class="tableDataValue">
                	<table>
	                	<tr>
		                	<td>
	                    		Calle*
	                    	</td>
	                		<td>
	                    		<html:text property="addressStreet" name="customerForm" styleId="addressStreetId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Numero*
	                    	</td>
	                		<td>
								<html:text property="addressNumber" name="customerForm" styleId="addressNumberId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Piso
	                    	</td>
	                		<td>
								<html:text property="addressFloor" name="customerForm" styleId="addressFloorId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Departamento
	                    	</td>
	                		<td>
								<html:text property="addressRoom" name="customerForm" styleId="addressRoomId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		C&oacute;digo Postal
	                    	</td>
	                		<td>
								<html:text property="addressZipCode" name="customerForm" styleId="addressZipCodeId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Ciudad*
	                    	</td>
	                		<td>
								<html:text property="addressCity" name="customerForm" styleId="addressCityId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Localidad*
	                    	</td>
	                		<td>
								<html:text property="addressTown" name="customerForm" styleId="addressTownId" />
	                    	</td>
                    	</tr>
                    </table>
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
            	<td class="tableDataTitle">
            		Contacto
            	</td>
        		<td class="tableDataValue">
					<html:text property="contact" name="customerForm" styleId="contactId" size="50" maxlength="75" />
            	</td>
        	</tr>
        </table>
    
        <br/>
        <div id="clear"></div>
    	<p class="mensajeCamposObligatorios">Los campos marcados con un asterisco (*) son obligatorios.</p>
    	<div id="clear"></div>
        
        <%-- Solo los administradores pueden modificar un cliente, pero verlo, pueden todos --%>
        <security:securizedContent roles="administrador,secretaria">
            <div class="panelButton">
                <input type="button" value="Modificar" onclick="modify();" title="Ver datos del cliente..." class="button">
                <input type="button" value="Ver Cuenta Corriente" onclick="showCustomerAccount();" title="Ver la cuenta corriente del cliente ..." class="button">
            </div>  
        </security:securizedContent>
    
    </div>

</html:form>


<%-- Inyectados por Javascript --%>
<div id="modifyDivId" class="hideClass">
    <html:form action="/protected/modifyCustomer" styleId="modifyCustomerFormId">
        <html:hidden property="id" value="" styleId="modifyId" />
        <html:hidden property="name" value="" styleId="modifyNameId" />
        <html:hidden property="corporateName" value="" styleId="modifyCorporateNameId" />
        <html:hidden property="document" value="" styleId="modifyDocumentId" />
        <html:hidden property="terms" value="" styleId="modifyTermsId" />
        <html:hidden property="email" value="" styleId="modifyEmailId" />
        <html:hidden property="phone" value="" styleId="modifyPhoneId" />
        <html:hidden property="mobile" value="" styleId="modifyMobileId" />
        <html:hidden property="addressStreet" value="" styleId="modifyAddressStreetId" />
        <html:hidden property="addressNumber" value="" styleId="modifyAddressNumberId" />
        <html:hidden property="addressFloor" value="" styleId="modifyAddressFloorId" />
        <html:hidden property="addressRoom" value="" styleId="modifyAddressRoomId" />
        <html:hidden property="addressZipCode" value="" styleId="modifyAddressZipCodeId" />
        <html:hidden property="addressCity" value="" styleId="modifyAddressCityId" />
        <html:hidden property="addressTown" value="" styleId="modifyAddressTownId" />
        <html:hidden property="contact" value="" styleId="modifyContactId" />
    </html:form>
</div>

<%-- Inyectados por Javascript. Es para mostrar la cuenta corriente --%>
<div id="showCustomerAccountDiv" class="hideClass">
    <html:form action="/protected/showCustomerAccount" styleId="showCustomerAccountFormId">
        <html:hidden property="customerId" value="" styleId="customerIdId" />
    </html:form>
</div>
